<?php

class Controller_Index extends Controller_TemplateNew
{
    public $_section;
    
	public function  before() {
		parent::before();
		$this->db = Database::instance();
		$this->mod = Model::factory('directory');
		$this->section = 'Home - ';
                
                $this->_section = 'index';

		$this->template->description = $this->settings['description'];
		$this->template->keywords = $this->settings['keywords'];
		$this->template->linkSettings = $this->settings;
                
                $this->template->header->active='index';
                
	}
    
	public function actionIndex()
	{
		$this->template->title = $this->section.$this->settings['title'];
		$this->template->content = new View('index/index');
                $this->template->content->bottomblock = new View('index/bottomblock');
                $this->template->content->downblock = new View('index/downblock');

                //list of catalog
                $signList = $this->mod->getCategories('catalog', 'position');
                $this->template->content->bottomblock->signList = $signList;
                
                
                $mainBlock = $this->mod->getItem(91, $this->_section);
                $this->template->content->mainBlock = $mainBlock;
                $centrBlock = $this->mod->getItem(92, $this->_section);
                $this->template->content->centrBlock = $centrBlock;
                $rightBlock = $this->mod->getItem(93, $this->_section);
                $this->template->content->rightBlock = $rightBlock;
                
                $mostPopular = $this->mod->getItem(94, $this->_section);
                $this->template->content->bottomblock->mostPopular = $mostPopular;
                $bottomBlock = $this->mod->getItem(95, $this->_section);
                $this->template->content->bottomblock->bottomBlock = $bottomBlock;
                
                $signsList = $this->mod->getCategories($this->_section, 'position');
                $this->template->content->signList = $signsList;
                
                $allImages = $this->mod->getImagesByItem($this->_section);
                if (isset($allImages[$mainBlock['id']])) {
                    foreach ($allImages[$mainBlock['id']] as $key=>$value) {
                        $allImages[$mainBlock['id']][$key]['imgPath'] = $this->mod->imagePath($value,'main');
                    }
                }
                if (isset($allImages[$centrBlock['id']])) {
                    foreach ($allImages[$centrBlock['id']] as $key=>$value) {
                        $allImages[$centrBlock['id']][$key]['imgPath'] = $this->mod->imagePath($value,'thumbs');
                    }
                }
                if (isset($allImages[$rightBlock['id']])) {
                    foreach ($allImages[$rightBlock['id']] as $key=>$value) {
                        $allImages[$rightBlock['id']][$key]['imgPath'] = $this->mod->imagePath($value,'main');
                    }
                }
                //Most popular and bottom block
                if (isset($allImages[$mostPopular['id']])) {
                    foreach ($allImages[$mostPopular['id']] as $key=>$value) {
                        $allImages[$mostPopular['id']][$key]['imgPath'] = $this->mod->imagePath($value,'main');
                    }
                }
                if (isset($allImages[$bottomBlock['id']])) {
                    foreach ($allImages[$bottomBlock['id']] as $key=>$value) {
                        $allImages[$bottomBlock['id']][$key]['imgPath'] = $this->mod->imagePath($value,'main');
                    }
                }
                
                if (isset($allImages)) {
                    $this->template->content->allImages = $allImages;
                }
                
                
                $this->addScript('/scripts/jquerytools/jquery.rotate.js');
                $this->addScript('/scripts/jquerytools/jquery.tinycarousel.min.js');
                $this->addScript('/scripts/jquerytools/jquery.cycle.js');
//                $this->addStyle('/styles/anythingslider/slider.css');
	}
}